package com.jlkf.service.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.springframework.util.StringUtils;

/**
 * 写文件
 * @author DN
 *
 */
public class FileWriteUtils {

	public String createFile(String result){
		if (!StringUtils.isEmpty(result)) {
			 File file = new File("d:/temp", "addfile.txt");  
			//把字符串转换成list
			if (!file.exists()) {
				try {
					file.createNewFile();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	            System.err.println(file + "已创建！");
	        }
			 byte bt[] = new byte[1024];  
		        bt = result.getBytes();  
		        try {  
		            FileOutputStream in = new FileOutputStream(file);  
		            try {  
		            	   in.write(bt, 0, bt.length);  
			                in.close(); 
		                // boolean success=true;  
		                // System.out.println("写入文件成功");  
		            } catch (IOException e) {  
		                // TODO Auto-generated catch block  
		                e.printStackTrace();  
		            }  
		        } catch (FileNotFoundException e) {  
		            // TODO Auto-generated catch block  
		            e.printStackTrace();  
		        }  
		}
		return result;
	} 
	
	
}
